const { Sequelize } = require("sequelize");
const { isRequired } = require("../utils");

module.exports = (sequelize, DataTypes) => {
  const AreaIcon = sequelize.define(
    "AreaIcon",
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: Sequelize.UUIDV4,
        //是否允许为空
        allowNull: false,
        //是否为主键
        primaryKey: true,
        //备注
        comment: "图标id",
      },
      areaId: {
        type: DataTypes.UUID,
        comment: "区域id",
        allowNull: false,
        validate: isRequired("区域id"),
      },
      iconId: {
        type: DataTypes.UUID,
        comment: "图标id",
        allowNull: false,
        validate: isRequired("图标id"),
      },
      info: {
        type: DataTypes.STRING,
        comment: "图标信息",
        allowNull: false,
        validate: isRequired("图标地址"),
      },
    },
    {
      timestamps: true,
      tableName: "map_area_icon",
      createdAt: "createTime",
      updatedAt: "updateTime",
      comment: "区域图标表",
    }
  );
  AreaIcon.associate = function (db) {
    db.AreaIcon.belongsTo(db.Icon, {
      foreignKey: "iconId",
      as: "iconInfo",
    });
  };
  return AreaIcon;
};
